package com.dongdong.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.dongdong.data.Page;
import com.dongdong.mapper.TbTypeTemplateMapper;
import com.dongdong.pojo.TbTypeTemplate;
import com.dongdong.pojo.TbTypeTemplateExample;
import com.dongdong.service.TypeTemplateService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;
import java.util.List;

@Service
@org.springframework.stereotype.Service
public class TypeTemplateServiceImpl implements TypeTemplateService {

    @Autowired
    private TbTypeTemplateMapper tbTypeTemplateMapper;

    //模糊查询分页
    @Override
    public Page<TbTypeTemplate> selectAll(String name, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        TbTypeTemplateExample te = new TbTypeTemplateExample();
        te.createCriteria().andNameLike(name);
        List<TbTypeTemplate> templateList = tbTypeTemplateMapper.selectByExample(te);
        PageInfo<TbTypeTemplate> info = new PageInfo<>(templateList);
        return new Page<>(info.getPageNum(),info.getPageSize(),info.getTotal(),info.getPages(),info.getList());
    }

    @Override
    public int insert(TbTypeTemplate tbTypeTemplate) {
        return tbTypeTemplateMapper.insertSelective(tbTypeTemplate);
    }

    @Override
    public TbTypeTemplate selectById(Long id) {
        return tbTypeTemplateMapper.selectByPrimaryKey(id.longValue());
    }

    @Override
    public int updateInfo(TbTypeTemplate tbTypeTemplate) {
        return tbTypeTemplateMapper.updateByPrimaryKeySelective(tbTypeTemplate);
    }

    @Override
    public int deleteAll(Long[] ids) {
        TbTypeTemplateExample te = new TbTypeTemplateExample();
        te.createCriteria().andIdIn(Arrays.asList(ids));
        return tbTypeTemplateMapper.deleteByExample(te);
    }
    @Override
    public List<TbTypeTemplate> selectInfo() {
        return tbTypeTemplateMapper.selectByExample(null);
    }

    @Override
    public TbTypeTemplate selectInfo(Long id) {
        return tbTypeTemplateMapper.selectByPrimaryKey(id);
    }
}
